package com.java.simple.study.jvm.gc;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author zhoujunlin
 * @date 2021/12/18
 * @desc 演示垃圾回收信息
 * -Xms20m -Xmx20m -Xmn10m -XX:+UseSerialGC -XX:+PrintGCDetails -verbose:gc
 **/
public class Demo7_3 {

    private static final int _512KB = 512 * 1024;
    private static final int _1MB = 1 * 1024 * 1024;
    private static final int _6MB = 6 * 1024 * 1024;
    private static final int _7MB = 7 * 1024 * 1024;
    private static final int _8MB = 8 * 1024 * 1024;

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            List<byte[]> list = new ArrayList<>();
            list.add(new byte[_8MB]);  // 大对象直接放入到老年代了
            list.add(new byte[_8MB]);
        }).start();

        TimeUnit.SECONDS.sleep(2);
        System.out.println("============sleep============");
        // 结论： 线程中的oom不会影响进程的运行
    }

}
